using SDK.Scripts.Utils;
using UnityEngine;

namespace SDK.Scripts.App
{
	public class App : MonoBehaviour
	{
		private static App _instace;

		public static App Instance => _instace;

		public static void CreateSDK(string sdkName)
		{
			GameObject gameObject = new GameObject();
			gameObject.name = sdkName;
			gameObject.AddComponent<App>();
		}

		private static void Log(object msg)
		{
			UnityEngine.Debug.Log(msg);
		}

		private static void LogWarning(object msg)
		{
			UnityEngine.Debug.LogWarning(msg);
		}

		private static void LogError(object msg)
		{
			UnityEngine.Debug.LogError(msg);
		}

		private static void setItem(string key, string value)
		{
			PlayerPrefs.SetString(key, value);
		}

		private static string getItem(string key, string value)
		{
			return PlayerPrefs.GetString(key, value);
		}

		private void Awake()
		{
			if (_instace != null)
			{
				UnityEngine.Object.Destroy(base.gameObject);
				return;
			}
			Object.DontDestroyOnLoad(base.gameObject);
			_instace = this;
			UnityEngine.Debug.Log("启动SDK");
			Debuger.debugerEvent += delegate(string methonName, object msg)
			{
				if (methonName != null)
				{
					if (!(methonName == "log") && !(methonName == "logDebug"))
					{
						if (!(methonName == "logWarning"))
						{
							if (methonName == "LogError")
							{
								LogError(msg);
							}
						}
						else
						{
							LogWarning(msg);
						}
					}
					else
					{
						Log(msg);
					}
				}
			};
			UnityEngine.Debug.Log("开启日志调试系统");
			Prefs.PrefsEvent += delegate(string type, string key, string value)
			{
				if (type == "SET")
				{
					setItem(key, value);
				}
				else if (type == "GET")
				{
					return getItem(key, value);
				}
				return string.Empty;
			};
		}

		private void Update()
		{
			Common.SendMessageByMainThread();
		}

		private void OnCallBack(string msg)
		{
			Debuger.Log($"回调成功 {msg}");
			GameSDK.GamePlat.OnCallBack(msg);
		}
	}
}
